package com.SmartCare.controller.client;

import com.SmartCare.common.Result;
import com.SmartCare.common.dto.medicine.MedicineDTO;
import com.SmartCare.service.medicine.MedicationListService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("/client/medication_list")
@Api(tags = "C端药单控制器")
@Slf4j
public class MedicineListController {
    @Resource
    MedicationListService medicationListService;

    /**
     * 查询老人正在服用的药单记录
     */
    @GetMapping("/query")
    public Result getListsByElderId(@RequestParam Long elderlyId) {
        return medicationListService.getListsByElderId(elderlyId);
    }


    /**
     * 获取老人所有的药单记录
     */
    @GetMapping("/selectAll")
    public Result getAllById(@RequestParam Long elderlyId) {
        return medicationListService.getAllById(elderlyId);
    }


    /**
     * 具体药物记录添加
     * @param medicineDTO 药物接收对象
     */
    @PostMapping("/add")
    @Transactional
    public Result medicineAdd(@RequestBody MedicineDTO medicineDTO,
                              @RequestParam(required = false) String listId) {
        return medicationListService.medicineAdd(medicineDTO, listId);
    }
}
